'''
Created on Jan 28, 2013

@author: kafkef
'''


from PyQt4.QtGui import *
from PyQt4.QtCore import Qt, QSettings

class RemoteTable(QTableWidget):
    def __init__(self, name):
        super(RemoteTable, self).__init__()
        self.name = name
        self.horizontalHeader().setStretchLastSection(True)
        self.horizontalHeader().setDefaultAlignment(Qt.AlignLeft)
        self.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.setSortingEnabled(True)

    def setItem(self, row, column, item):
        assert isinstance(item, QTableWidgetItem)
        item.setBackgroundColor(QColor(Qt.lightGray))
        return super(RemoteTable, self).setItem(row, column, item)

    def save_settings(self):
        settings = QSettings()
        settings.beginGroup(self.name)
        settings.setValue("Header", self.horizontalHeader().saveState())
        settings.endGroup()
    
    def restore_settings(self):
        settings = QSettings()
        settings.beginGroup(self.name)
        self.horizontalHeader().restoreState(settings.value("Header", "").toByteArray())
        settings.endGroup()